package com.vodone.v1pin.component.core
{
	import caurina.transitions.Tweener;
	
	import flash.events.Event;
	
	import mx.controls.Image;
	import mx.controls.SWFLoader;
	import mx.events.PropertyChangeEvent;
	
	public class LoadingImage extends Image
	{
		public function LoadingImage()
		{
			super();
			addEventListener(Event.COMPLETE , completeHandler );
		}
		
		public override function set source(value:Object):void{
			super.source = value;
			if( null != loading )
			{
				showLoading();
			}
		}
		
		public function showLoading():void
		{
			loading.visible = true;
		}
		public function hideLoading():void
		{
			loading.visible = false;
		}
		private function completeHandler( e:Event ) :void
		{
			hideLoading();
//			this.alpha = 0;
//			Tweener.addTween( this,{alpha:1,time:1,transition:"easeOutQuint",onComplete:endEffect} );
		}
		
		private function endEffect():void
		{
			Tweener.removeTweens( this );
		}
		
		private var loading:SWFLoader = new SWFLoader();;
		protected override function createChildren():void
		{
			super.createChildren();
			loading.source = "assets/loading/loading2.swf";
			loading.width = 40;
			loading.height = 40;
			addChild(loading);
		}
		protected override function updateDisplayList(w:Number, h:Number):void
		{
			super.updateDisplayList( w , h );
			var loadingX:Number = ( w - loading.width ) / 2;
			var loadingY:Number = ( h - loading.height ) / 2;
			loading.move( loadingX , loadingY  );
		}
	}
}